package com.dimpt.cloud.common.config;

/**
 *
 * @author liujf
 *
 */
public enum ResponseInfo {

    SUCCESS(200,"SUCCESS"),

    //用户认证异常
    USERNAME_ERROR(1001,"用户名错误"),
    USERNAME_EMPTY(1002,"用户名不能为空"),
    PASSWORD_ERROR(1003,"密码错误"),
    PASSWORD_EMPTY(1004,"密码不能为空"),
    AUTH_FAILED(1005,"认证失败"),

//    CREATE_FAILED(301,"创建失败"),

//    PAGE_ERROR(7000, "当前页数大于总数"),

    //系统错误异常
    UNKNOW_ERROR(8000, "未知错误"),

    PARAM_ERROR(9000, "参数格式错误"),

    SERVER_ERROR(9999, "服务器异常");

    private int errorCode;
    private String errorMessage;

    ResponseInfo(int code, String msg) {
        this.errorCode = code;
        this.errorMessage = msg;
    }
    public int getErrorCode() {
        return errorCode;
    }

    public String getErrorMsg() {
        return errorMessage;
    }

    public static String getResponseErrorMsg(String code) {

        for(ResponseInfo responseInfo: ResponseInfo.values()) {

            if(code.equals(responseInfo.getErrorCode())) {

                return responseInfo.getErrorMsg();
            }
        }
        return SERVER_ERROR.getErrorMsg();
    }

    public static int getResponseErrorCode(String msg) {
        if(msg == null) {

            return UNKNOW_ERROR.getErrorCode();
        }
        for(ResponseInfo responseInfo: ResponseInfo.values()) {

            if(msg.equals(responseInfo.getErrorMsg())) {
                return responseInfo.getErrorCode();
            }
        }
        return SERVER_ERROR.getErrorCode();
    }
}
